<template>
  <div>
    <TopFilter :list="topFilterList" :cols="4" :labelWidth="80" :collapse="false" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="partPartInfoManageContactsCustomerIndex"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="
        columns => {
          this.columns = columns;
        }
      "
      :isSelectColumn="false"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle">新增</el-button>
      </template>
    </FilterTable>
    <Drawer :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <add :type="handleType" :rowData="formData" @close="closeHandler" />
    </Drawer>
    <!-- <Drawer
      :visible.sync="visibleEdit"
      :title="dialogTitleEdit"
      destroyOnClose
      width="700"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <edit :type="handleTypeEdit" :rowData="formDataEdit" @close="closeHandlerEdit" @reEdit="reEdit" />
    </Drawer>-->
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { queryBusinessCustomer, customersSelect } from '@/api/part/partInfoManage/contactsCustomer';
import add from './tabs/add';

export default {
  name: 'monitorInfo',
  components: {
    add
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', edit: '编辑', show: '显示' };
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchApi: queryBusinessCustomer,
      fetchParams: {},
      handleType: '',
      handleTypeEdit: '',
      formData: {},
      formDataEdit: {},
      dialogTitle: '',
      dialogTitleEdit: '',
      visible: false,
      visibleEdit: false
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.customersSelect();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'SELECT',
          label: '供应商类型',
          fieldName: 'customerTypeCode',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '供应商代码',
          fieldName: 'customerCode',
          placeholder: '客户代码'
        },
        {
          type: 'INPUT',
          label: '供应商名称',
          fieldName: 'customerName',
          placeholder: '客户名称'
        },
        {
          type: 'INPUT',
          label: '供应商拼音',
          fieldName: 'customerSpell',
          placeholder: '请输入...'
        },
        {
          type: 'SELECT',
          label: '数据来源',
          fieldName: 'oemTag',
          placeholder: '请选择...',
          itemList: this.createDictList('1045')
        },
        {
          type: 'SELECT',
          label: '是否有效',
          fieldName: 'isValid',
          placeholder: '请选择...',
          itemList: this.createDictList('1004')
        }
      ];
    },
    createTableColumns: function() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: (props, h) => {
            return <span> {props.row.index + 1} </span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button disabled={props.row.oemTag == 10451002} size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
              </div>
            );
          }
        },
        {
          title: '供应商代码',
          dataIndex: 'customerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '供应商名称',
          dataIndex: 'customerName',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '供应商简称',
          dataIndex: 'customerShortName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '供应商拼音',
          dataIndex: 'customerSpell',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '供应商类型名称',
          dataIndex: 'customerTypeName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人',
          dataIndex: 'contactorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人电话',
          dataIndex: 'contactorPhone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人手机',
          dataIndex: 'contactorMobile',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '价格系数',
        //   dataIndex: 'priceRate',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '销售基价',
        //   dataIndex: 'salesBasePriceType',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   render: (props, h) => {
        //     return <span> {this.createDictText(props.row.salesBasePriceType, '8050')} </span>;
        //   }
        // },
        {
          title: '是否有效',
          dataIndex: 'isValid',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004),
          render: (props, h) => {
            return <span> {this.createDictText(props.row.isValid, '1004')} </span>;
          }
        },
        {
          title: '数据来源',
          dataIndex: 'oemTag',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1045),
          render: (props, h) => {
            return <span> {/1045/gi.test(props.row.oemTag) ? this.createDictText(props.row.oemTag, '1045') : ''} </span>;
          }
        },
        // {
        //   title: '税率',
        //   dataIndex: 'tax',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number'
        // },
        {
          title: '地址',
          dataIndex: 'address',
          sorter: true,
          filter: true,
          width: 180,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '邮编',
          dataIndex: 'zipCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        }
        // {
        //   title: '供应商类型',
        //   dataIndex: 'providerType',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   render: (props, h) => {
        //     return <span> {this.createDictText(props.row.providerType, '8101')} </span>;
        //   }
        // },
        // {
        //   title: '开户行',
        //   dataIndex: 'bank',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '银行账号',
        //   dataIndex: 'bankAccount',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '税号',
        //   dataIndex: 'remark',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '整车业务',
        //   dataIndex: 'vehicleBusiness',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '配件业务',
        //   dataIndex: 'partBusiness',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '精品业务',
        //   dataIndex: 'boutiqueBusiness',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '礼品业务',
        //   dataIndex: 'gitBusiness',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '销售公司',
        //   dataIndex: 'salesCompany',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '停用日期',
        //   dataIndex: 'disableDate',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'date-range',
        //   dateFormat: 'yyyy-MM-dd'
        // }
      ];
    },
    findIndex(arr, fieldName) {
      // console.log(arr);
      let indexR = -1;
      arr.forEach((x, index) => {
        if (x.fieldName == fieldName) {
          // console.log(x);
          // console.log(index);
          indexR = index;
        }
      });
      return indexR;
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    showHandler() {
      this.dialogTitle = `供应商${this.conf[this.handleType]}`;
      this.visible = true;
    },
    // showHandler1() {
    //   this.dialogTitleEdit = `供应商${this.conf[this.handleTypeEdit]}`;
    //   this.visibleEdit = true;
    // },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    async customersSelect() {
      let res = await customersSelect();
      let json = res.data.rows.map(s => ({
        value: s.customerTypeCode,
        text: s.customerTypeName
      }));
      this.topFilterList[this.findIndex(this.topFilterList, 'customerTypeCode')].itemList = json;
    }
    // closeHandlerEdit(val, type) {
    //   this.visible = val;
    //   if (type === 'refresh') {
    //     // 重新加载
    //     this.fetchParams = { ...this.fetchParams };
    //   }
    // },
    // reAdd(a, b){
    //   this.visible = false;
    //   this.reSearch(a, b);
    // },
    // reEdit(a, b){
    //   this.visibleEdit = false;
    //   this.reSearch(a, b);
    // },
    // async reSearch(a, b){
    //   console.log(a, b);
    //   let res = {};
    //   b = a == 1 ? b : {};
    //   res = await queryBusinessCustomer(b);
    //   console.log(res);
    //   this.BaseTable.EXECUTE_INSERT(res.data.rows);
    // }
  }
};
</script>

<style scoped></style>
